//
// Created by Martin on 2021/10/2.
//

#include "Flyweight.h"
#include "FlyweightFactory.h"
#include "UnsharedConcreteFlyweight.h"
#include "ConcreteFlyweight.h"

#include <string>
#include <iostream>

using namespace std;

/**
 * 客户端测试享元模式
 * @note 根据字符串辨识具体的享元对象. 例程中, pool是静态成员, 无需考虑其元素的释放问题
 * @see https://www.cnblogs.com/adamjwh/p/9070107.html
 */
int main()
{
    int extrinsic = 22;

    string s = "X";
    Flyweight *flyweightX = FlyweightFactory::getFlyweight(s);
    flyweightX->operation(++extrinsic);

    s = "Y";
    Flyweight *flyweightY = FlyweightFactory::getFlyweight(s);
    flyweightY->operation(++extrinsic);

    s = "Z";
    Flyweight *flyweightZ = FlyweightFactory::getFlyweight(s);
    flyweightZ->operation(++extrinsic);

    s = "X";
    Flyweight *flyweightRefX = FlyweightFactory::getFlyweight(s);
    flyweightRefX->operation(++extrinsic);

    s = "X";
    Flyweight *unsharedFlyweight = new UnsharedConcreteFlyweight(s);
    unsharedFlyweight->operation(++extrinsic);

    delete unsharedFlyweight;
    return 0;
}